﻿Imports ACompany.OrderProcessing.Presentation
Imports ACompany.OrderProcessing.Infrastructure

Partial Class UserControls_Customer_CustomerList
    Inherits System.Web.UI.UserControl
    Implements ICustomerListView

    Private _Presenter As CustomerListPresenter

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        _Presenter = New CustomerListPresenter(Me)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _Presenter.Display()
    End Sub

    Public WriteOnly Property Customers() As System.Collections.Generic.List(Of ACompany.OrderProcessing.Model.Customer) Implements ACompany.OrderProcessing.Presentation.ICustomerListView.Customers
        Set(ByVal value As System.Collections.Generic.List(Of ACompany.OrderProcessing.Model.Customer))
            Me.grdCustomers.DataSource = value
            Me.grdCustomers.DataBind()
        End Set
    End Property

    Protected Sub btnNewCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewCustomer.Click
        Response.Redirect("CustomerDetail.aspx?CustomerAction=Detail")
    End Sub

    Protected Sub grdCustomers_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdCustomers.RowCommand

        Select Case e.CommandName.ToLower()

            Case "deletecustomer"

                _Presenter.RemoveCustomerBy(New Guid(e.CommandArgument.ToString))

        End Select
    End Sub

    Public Sub ErrorMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ErrorMessage
        If String.IsNullOrEmpty(Message) Then
            pnlError.Visible = False
        Else
            pnlError.Visible = True
        End If
        Me.litErrorMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub InfoMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.InfoMessage
        If String.IsNullOrEmpty(Message) Then
            pnlInfo.Visible = False
        Else
            pnlInfo.Visible = True
        End If
        Me.litInfoMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub ViewTitle(ByVal title As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ViewTitle

    End Sub


    Public Function MyMethod() As String

        HttpContext.Current.Trace.Warn("Start MyMethod()")

        ' method runs.....

        HttpContext.Current.Trace.Warn("End MyMethod()")

    End Function
End Class
